(require '[fx-clj.internal.util])
(fx-clj.internal.util/ns-start-loading 'fx-clj.impl.elements)

(ns ^:no-doc fx-clj.impl.elements
  (:import (java.lang.reflect Modifier Constructor)))

;; <<----------------------
(fx-clj.internal.util/ns-libs-loaded 'fx-clj.impl.elements)
;; ---------------------->>

(def element-factories (atom {}))

(defn get-default-ctr [cls]
  (try
    (.getConstructor cls nil)
    (catch Throwable _)))

(def load-class
  (memoize
    (fn [^String class-name]
      (Class/forName class-name))))

(def get-factory
  (memoize
    (fn [^String full-class-name]
      (let [cls (load-class full-class-name)
            ^Constructor ctr (get-default-ctr cls)]
        (when (and ctr (not (Modifier/isAbstract (.getModifiers cls))))
          (with-meta
            (fn []
              (.newInstance ctr nil))
            {::constructor ctr ::class cls}))))))



(fx-clj.internal.util/ns-loaded 'fx-clj.impl.elements)